package com.gupao.pattern.proxy.dynamicproxy.jdk;

import com.gupao.pattern.proxy.Person;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class MeiPoProxy implements InvocationHandler {

    private Person person;


    public Object getInstance(Person person){
        this.person=person;
        Class<? extends Person> clazz = this.person.getClass();
        return Proxy.newProxyInstance(clazz.getClassLoader(),clazz.getInterfaces(),this);
    }



    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("物色对象");
        Object obj = method.invoke(this.person, args);
        System.out.println("对象找到");
        return null;
    }


    public void test(String str,int age){

    }


    public static void main(String[] args) {
        Person person= (Person) new MeiPoProxy().getInstance(new Girl());
        //person.findLove();
    }
}
